package com.example.demo.redis;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundValueOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;


@Component
public class MyRedisTemplate {
	
	
	@Autowired
	private  StringRedisTemplate redisTemplate;
	

	
	private static final Logger logger = LoggerFactory.getLogger(MyRedisTemplate.class);
	
	public boolean setBit(String key, long offset, boolean isShow) {
		boolean result = false;
		try {
			ValueOperations<String, String> operations = redisTemplate.opsForValue();
			operations.setBit(key, offset, isShow);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public boolean set(final String key, String value) {
		boolean result = false;
		try {
			// ValueOperations<String,String> operations = redisTemplate.opsForValue();
			BoundValueOperations<String, String > ops =  redisTemplate.boundValueOps(key);
			ops.set(value);
			// operations.set(key, value);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("错误"+e);
		}
		return result;
	}
	
	public Object get(final String key) {
		Object result = null;
		ValueOperations<String,String> operations = redisTemplate.opsForValue();
		result = operations.get(key);
		return result;
	}
}
